package com.micro.ai.template.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.micro.ai.template.entity.AgentInstance;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * Agent实例Mapper
 *
 * @author micro-ai
 * @since 0.0.1
 */
@Mapper
public interface AgentInstanceMapper extends BaseMapper<AgentInstance> {

    /**
     * 根据模板ID查询Agent实例
     */
    @Select("SELECT * FROM agent_instances WHERE template_id = #{templateId} AND status != 'DELETED'")
    List<AgentInstance> selectByTemplateId(@Param("templateId") String templateId);

    /**
     * 根据创建者查询Agent实例
     */
    @Select("SELECT * FROM agent_instances WHERE created_by = #{createdBy} AND status != 'DELETED' ORDER BY created_at DESC")
    List<AgentInstance> selectByCreatedBy(@Param("createdBy") String createdBy);

    /**
     * 统计模板使用次数
     */
    @Select("SELECT COUNT(*) FROM agent_instances WHERE template_id = #{templateId} AND status != 'DELETED'")
    Integer countByTemplateId(@Param("templateId") String templateId);
}

